package com.xf.system.controller;

import com.xf.system.common.facade.DeptFacade;
import com.xf.system.http.req.dept.DeptAddReqDTO;
import com.xf.system.http.req.dept.DeptListReqDTO;
import com.xf.system.http.req.dept.DeptUpdateReqDTO;
import com.xf.system.http.vo.dept.DeptTreeVO;
import com.xf.system.http.vo.dept.DeptVO;
import com.xf.system.response.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author xiefengf
 */
@Api(tags = "部门服务Api")
@Slf4j
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Resource
    private DeptFacade deptFacade;

    @GetMapping("/listDeptTree")
    @Operation(summary = "当前部门列表树型查询", method = "GET")
    public ApiResult<DeptVO> listDeptTree(@ModelAttribute DeptListReqDTO reqDto) {
        DeptVO vo = deptFacade.listDeptTree(reqDto);
        return ApiResult.success(vo);
    }

    @GetMapping("/getDeptById/{id}")
    @Operation(summary = "通过部门id查询部门详情信息", method = "GET")
    public ApiResult<DeptTreeVO> getDeptById(@PathVariable("id") Long id) {
        DeptTreeVO vo = deptFacade.getDeptById(id);
        return ApiResult.success(vo);
    }

    @PostMapping("/saveDept")
    @Operation(summary = "新增部门信息", method = "POST")
    public ApiResult<Boolean> saveDept(@RequestBody @Valid DeptAddReqDTO reqDto) {
        Boolean aBoolean = deptFacade.saveDept(reqDto);
        return ApiResult.success(aBoolean);
    }

    @PutMapping("/updateDept")
    @Operation(summary = "更新部门信息", method = "PUT")
    public ApiResult<Boolean> updateDept(@RequestBody @Valid DeptUpdateReqDTO reqDto) {
        Boolean aBoolean = deptFacade.updateDept(reqDto);
        return ApiResult.success(aBoolean);
    }

    @DeleteMapping("/deleteDept/{id}")
    @Operation(summary = "删除部门信息", method = "DELETE")
    public ApiResult<Boolean> deleteDept(@PathVariable(value = "id") Long id) {
        Boolean aBoolean = deptFacade.deleteDept(id);
        return ApiResult.success(aBoolean);
    }

}
